﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="NewsTypeList.aspx.cs" Inherits="ExaminationSys.View.News.NewsTypeList" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register src="NewsTypeEdit.ascx" tagname="NewsTypeEdit" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
        var newsTypeEditDetailsRender = function () {
            return '<img class="ImageEdit" ext:qtip="编辑" style="cursor:pointer;" src="../../images/vcard_edit.png" />';
        };
        var template = '<span style="color:{0};">{1}</span>';
        var StatusRaw = function (value) {
            switch (value) {
                case 1:
                    return Ext.String.format(template, "green", "启用");
                case 0:
                    return Ext.String.format(template, "red", "停用");
                default:
                    return Ext.String.format(template, "red", "其它");
            }
        };
        var FormatColorTemplete = '<span style="color:{0};">{1}</span>';
        var FormatColor = function (value) {
            return Ext.String.format(FormatColorTemplete, (value > 0) ? "red" : "black", value);
        };
        var cellClick = function (view, cell, columnIndex, record, row, rowIndex, e) {
            var t = e.getTarget(),
                columnId = this.columns[columnIndex].id; // // Get column id
            if (columnId == "Details") {

                //the ajax call is allowed
                return true;
            }

            //forbidden
            return false;
        };

        var getGridSelected = function () {
            return App.GridPanelNewsType.GetSelectionModel()
            //return App.GridPanelNewsType.getSelectionModel().getSelected();
        };
        var MessageBoxWARNING = function (title, msg) {
            Ext.Msg.show({
                title: title,
                msg: msg,
                buttons: Ext.Msg.OK,
                icon: Ext.MessageBox.WARNING
            });
        };

        var prepare = function (grid, toolbar, rowIndex, record) {
            var firstButton = toolbar.items.get(0);

            if (record.data.FailedCount == 0) {
                firstButton.setDisabled(true);
                firstButton.setTooltip("没有选中任何记录");
            }
            //you can return false to cancel toolbar for this record
        };

        var reLoad = function () {
            GridPanelNewsType.reload();
        };
    </script>
</head>
<body>
    <form id="Form1" runat="server">
        <ext:ResourceManager runat="server"/>
         <ext:Store ID="StoreNewsType" runat="server" ShowWarningOnFailure="true" AutoLoad="true" OnReadData="StoreNewsType_RefreshData">
            <Model>
                <ext:Model ID="NewsTypeModel" runat="server" IDProperty="ID">
                    <Fields>
                        <ext:ModelField Name="ID"/>
                        <ext:ModelField Name="Name" />
                        <ext:ModelField Name="Status" Type="Int" />
                        <ext:ModelField Name="Description" />
                        <ext:ModelField Name="Opeator" />
                        <ext:ModelField Name="OpeatorTime" Type="Date" />
                    </Fields>
                </ext:Model>
            </Model>            
            <Sorters>
                <ext:DataSorter Property="OpeatorTime" Direction="DESC" />
            </Sorters>
            <Listeners>
                <Exception Handler="Ext.MessageBox.alert('Load failed', response.statusText);"></Exception>
            </Listeners>
        </ext:Store>
         <ext:ViewPort ID="ViewPort1" runat="server" Layout="fit">
        <Items>
        <ext:GridPanel 
            ID="GridPanelNewsType" 
            runat="server" 
            StoreID="StoreNewsType"             
            Header="false"
            Border="false"
            TrackMouseOver="true"
            AutoExpandColumn="Description"
            >
          <%--  <Loader>
                <LoadMask ShowMask="true" Msg="加载中..."></LoadMask>
            </Loader>--%>
            <TopBar>
                <ext:Toolbar ID="Toolbar1" runat="server">
                    <Items>
                        <ext:Button ID="BtnAdd" runat="server" Text="新增" Icon="UserAdd">
                        <DirectEvents>
                            <Click OnEvent="Add_Click"></Click>
                        </DirectEvents>
                        </ext:Button>
                        <ext:Button runat="server" ID="BtnRefresh" Text="刷新" Icon="ArrowRefresh" >                           
                               <Listeners>
                                    <Click Handler="#{StoreNewsType}.reload();"  />
                                </Listeners>                          
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <SelectionModel> 
             <ext:CheckboxSelectionModel  runat="server" Mode="Multi" />
            </SelectionModel>
            <ColumnModel runat="server">
			    <Columns>
                    <ext:Column runat="server" Header="ID" DataIndex="ID" Width="150" Hidden="true" />
                    <ext:Column  runat="server" Header="名称" DataIndex="Name" Width="100" />
                    <ext:Column  runat="server" Header="状态" DataIndex="Status" Width="100">
                         <Renderer Fn="StatusRaw" />
                    </ext:Column>
                    <ext:Column runat="server" Header="描述" DataIndex="Description" Width="100" />
                    <ext:Column runat="server" Header="操作者" DataIndex="Opeator" Width="100" />
                    <ext:DateColumn  runat="server" Header="操作时间" DataIndex="OpeatorTime" Format="yyyy-MM-dd HH:mm" />

                    <ext:Column 
                        ID="Details"                          
                        Text="编辑" 
                        Width="50" 
                        Align="Center" 
                        Fixed="true" 
                        MenuDisabled="true"
                        Resizable="false">
                        
                        <Renderer Fn="newsTypeEditDetailsRender" 
                        />          
                    </ext:Column>
			    </Columns>
            </ColumnModel>
            <Listeners>
                <CellClick Fn="cellClick" />
            </Listeners> 
            <DirectEvents>
                <CellClick
                    OnEvent="ShowDetails" 
                    Failure="Ext.MessageBox.alert('Load failed', 'Error during ajax event!');">
                    <EventMask ShowMask="true" Target="CustomTarget" CustomTarget="={#{GridPanelNewsType}.body}" />
                    <ExtraParams>
                        <ext:Parameter Name="id" Value="record.getId()" Mode="Raw" />
                    </ExtraParams>
                </CellClick>
                
            </DirectEvents>
            <View>
                <ext:GridView  runat="server" />
            </View>    

        </ext:GridPanel>

        </Items>
        </ext:ViewPort>
        <uc1:NewsTypeEdit ID="NewsTypeEditWindow" runat="server" />
    </form>
</body>
</html>
